home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / General / SpriteWorld 1.0b3 / Examples / SpriteTest / SpriteTest.c < prev    next >
Text File  |  1993-06-19  |  16KB  |  666 lines

  1. ///--------------------------------------------------------------------------------------
  2. // SpriteTest.c
  3. //
  4. // Created: 8/14/91 at 1:53 AM
  5. // By: Tony Myles
  6. //
  7. // Copyright © 1992-93 Tony Myles, All rights reserved worldwide.
  8. ///--------------------------------------------------------------------------------------
  9.  
  10.  
  11. #if THINK_C
  12. #ifndef __BDC__
  13. #include <BDC.h>
  14. #endif
  15. #else
  16. #ifndef __PACKAGES__
  17. #include <Packages.h>
  18. #endif
  19. #endif
  20.  
  21. #ifndef __DIALOGS__
  22. #include <Dialogs.h>
  23. #endif
  24.  
  25. #ifndef __RESOURCES__
  26. #include <Resources.h>
  27. #endif
  28.  
  29. #ifndef __MEMORY__
  30. #include <Memory.h>
  31. #endif
  32.  
  33. #ifndef __EVENTS__
  34. #include <Events.h>
  35. #endif
  36.  
  37. #ifndef __OSEVENTS__
  38. #include <OSEvents.h>
  39. #endif
  40.  
  41. #ifndef __TOOLUTILS__
  42. #include <ToolUtils.h>
  43. #endif
  44.  
  45. #ifndef __SEGLOAD__
  46. #include <SegLoad.h>
  47. #endif
  48.  
  49. #ifndef __SPRITEWORLD__
  50. #include <SpriteWorld.h>
  51. #endif
  52.  
  53. #ifndef __SPRITELAYER__
  54. #include <SpriteLayer.h>
  55. #endif
  56.  
  57. #ifndef __SPRITE__
  58. #include <Sprite.h>
  59. #endif
  60.  
  61. #ifndef __FRAME__
  62. #include <Frame.h>
  63. #endif
  64.  
  65. #ifndef __SPRITEWORLDUTILS__
  66. #include <SpriteWorldUtils.h>
  67. #endif
  68.  
  69. #include <GameUtils.h>
  70. #include <DebugUtils.h>
  71.  
  72. #include <BlitPixie.h>
  73. #include "SpriteTest.h"
  74.  
  75.  
  76. RgnHandle gWorkRgn = NULL;
  77.  
  78.  
  79. ///--------------------------------------------------------------------------------------
  80. // CreateSpriteTest
  81. ///--------------------------------------------------------------------------------------
  82.  
  83. OSErr CreateSpriteTest(
  84.     SpriteTestPtr* spriteTestP,
  85.     CWindowPtr srcWindowP)
  86. {
  87.     OSErr err = noErr;
  88.     SpriteTestPtr tempSpriteTestP;
  89.     SpriteWorldPtr spriteWorldP;
  90.     SpriteLayerPtr spriteLayerP;
  91.     SpritePtr testSpriteArray[kNumberOfTestSprites];
  92.     SpritePtr titleSpriteP;
  93.     FramePtr titleFrameP;
  94.     PixPatHandle pixPatH;
  95.     long spriteNum;
  96.     short oldResRefNum, curResRefNum;
  97.     Rect worldRect;
  98.  
  99.     *spriteTestP = NULL;
  100.  
  101.     gWorkRgn = NewRgn();
  102.  
  103.     SetPort((GrafPtr)srcWindowP);
  104.     worldRect = srcWindowP->portRect;
  105.  
  106.     tempSpriteTestP = (SpriteTestPtr)NewPtrClear((Size)sizeof(SpriteTestRec));
  107.  
  108.     if (tempSpriteTestP == NULL)
  109.     {
  110.         err = MemError();
  111.     }
  112.  
  113.     if (err == noErr)
  114.     {
  115.         err = SWEnterSpriteWorld();
  116.         
  117.     }
  118.  
  119.     if (err == noErr)
  120.     {
  121.             // create the sprite world
  122.         err = SWCreateSpriteWorldFromWindow(&spriteWorldP, srcWindowP, NULL);
  123.     }
  124.  
  125.     if (err == noErr)
  126.     {
  127.         tempSpriteTestP->spriteWorldP = spriteWorldP;
  128.  
  129.             // create the sprite layer
  130.         err = SWCreateSpriteLayer(&spriteLayerP);
  131.     }
  132.  
  133.     if (err == noErr)
  134.     {
  135.         oldResRefNum = CurResFile();
  136.         curResRefNum = OpenResFile("\pSpriteTest Frames");
  137.         err = ResError();
  138.     }
  139.  
  140.     if (err == noErr)
  141.     {
  142.         UseResFile(curResRefNum);
  143.  
  144.         tempSpriteTestP->spriteLayerP = spriteLayerP;
  145.  
  146.         err = SWCreateSpriteFromCIconResource(testSpriteArray, NULL, kTestCIconID, kNumberOfTestFrames, kFatMask);
  147.  
  148.         UseResFile(oldResRefNum);
  149.         CloseResFile(curResRefNum);
  150.     }
  151.  
  152.     if (err == noErr)
  153.     {
  154.         tempSpriteTestP->testSpriteArray[0] = testSpriteArray[0];
  155.  
  156.             // create our sprites
  157.         for (spriteNum = 1; spriteNum < kNumberOfTestSprites; spriteNum++)
  158.         {
  159.             err = SWCloneSprite(testSpriteArray[0], testSpriteArray + spriteNum, NULL);
  160.  
  161.             if (err == noErr)
  162.             {
  163.                 tempSpriteTestP->testSpriteArray[spriteNum] = testSpriteArray[spriteNum];
  164.             }
  165.             else
  166.             {
  167.                 break;
  168.             }
  169.         }
  170.     }
  171.  
  172.     if (err == noErr)
  173.     {
  174.         err = SWCreateSprite(&titleSpriteP, NULL, 1);
  175.     }
  176.  
  177.     if (err == noErr)
  178.     {
  179.         tempSpriteTestP->titleSpriteP = titleSpriteP;
  180.  
  181.             // create a frame for our sprite
  182.         err = SWCreateFrameFromPictResource(&titleFrameP, 128, 129, kFatMask);
  183.     }
  184.  
  185.     if (err == noErr)
  186.     {
  187.         tempSpriteTestP->titleFrameP = titleFrameP;
  188.         *spriteTestP = tempSpriteTestP;
  189.  
  190.         SWAddFrame(titleSpriteP, titleFrameP);
  191.  
  192.         for (spriteNum = 0; spriteNum < kNumberOfTestSprites; spriteNum++)
  193.         {
  194.             if (spriteNum == (kNumberOfTestSprites / 2))
  195.             {
  196.                 SWAddSprite(spriteLayerP, titleSpriteP);
  197.             }
  198.     
  199.                 // add the sprite in the layer
  200.             SWAddSprite(spriteLayerP, testSpriteArray[spriteNum]);
  201.         }
  202.  
  203.             // add the layer to the world
  204.         SWAddSpriteLayer(spriteWorldP, spriteLayerP);
  205.  
  206.         SWLockSpriteWorld(spriteWorldP);
  207.  
  208.         SetupSpriteTest(tempSpriteTestP);
  209.  
  210.         SWSetPortToBackGround(spriteWorldP);
  211.  
  212.         if (SWHasColorQuickDraw() && ((**srcWindowP->portPixMap).pixelSize > 1))
  213.         {
  214.                 // fill the sprite world with a pretty pattern
  215.             pixPatH = GetPixPat(kBackDropPixPatID);
  216.  
  217.             if (pixPatH != NULL)
  218.             {
  219.                 FillCRect(&worldRect, pixPatH);
  220.                 DisposePixPat(pixPatH);
  221.             }
  222.             else
  223.             {
  224.                 FillRect(&worldRect, qd.ltGray);
  225.             }
  226.         }
  227.         else
  228.         {
  229.             FillRect(&worldRect, qd.ltGray);
  230.         }
  231.  
  232.         SetPort((GrafPtr)srcWindowP);
  233.     }
  234.  
  235.     if (err != noErr)
  236.     {
  237.         DisposeSpriteTest(tempSpriteTestP);
  238.     }
  239.     
  240.     return err;
  241. }
  242.  
  243.  
  244. void DisposeSpriteTest(
  245.     SpriteTestPtr spriteTestP)
  246. {
  247.     long spriteNum;
  248.  
  249.     if (gWorkRgn != NULL)
  250.         DisposeRgn(gWorkRgn);
  251.  
  252.     if (spriteTestP != NULL)
  253.     {
  254.         if (spriteTestP->spriteWorldP != NULL)
  255.         {
  256.             SWUnlockSpriteWorld(spriteTestP->spriteWorldP);
  257.         }
  258.     
  259.         for (spriteNum = 0; spriteNum < kNumberOfTestSprites; spriteNum++)
  260.         {
  261.             if (spriteTestP->testSpriteArray[spriteNum] != NULL)
  262.             {
  263.                 SWDisposeSprite(spriteTestP->testSpriteArray[spriteNum], spriteNum == 0);
  264.             }
  265.         }
  266.  
  267.         if (spriteTestP->titleFrameP != NULL)
  268.         {
  269.             SWDisposeFrame(spriteTestP->titleFrameP);
  270.         }
  271.     
  272.         if (spriteTestP->titleSpriteP != NULL)
  273.         {
  274.             SWDisposeSprite(spriteTestP->titleSpriteP, false);
  275.         }
  276.     
  277.         if (spriteTestP->spriteLayerP != NULL)
  278.         {
  279.             SWDisposeSpriteLayer(spriteTestP->spriteLayerP);
  280.         }
  281.     
  282.         if (spriteTestP->spriteWorldP != NULL)
  283.         {
  284.             SWDisposeSpriteWorld(spriteTestP->spriteWorldP);
  285.         }
  286.  
  287.         DisposePtr((Ptr)spriteTestP);
  288.     }
  289.  
  290.     SWExitSpriteWorld();
  291. }
  292.  
  293.  
  294. void SetupSpriteTest(
  295.     SpriteTestPtr spriteTestP)
  296. {
  297.     register long spriteNum;
  298.     register SpritePtr testSpriteP;
  299.     short horizMoveDelta;
  300.     short vertMoveDelta;
  301.     Rect moveBoundsRect;
  302.  
  303.         // set up the sprites
  304.     for (spriteNum = 0; spriteNum < kNumberOfTestSprites; spriteNum++)
  305.     {
  306.         testSpriteP = spriteTestP->testSpriteArray[spriteNum];
  307.  
  308.         horizMoveDelta = GetRandom(2, 6);
  309.         vertMoveDelta = GetRandom(2, 6);
  310.  
  311.             // calculate the movement boundary rectangle
  312.         moveBoundsRect = spriteTestP->spriteWorldP->windowFrameP->frameRect;
  313.         //InsetRect(&moveBoundsRect, horizMoveDelta / 2, vertMoveDelta / 2);
  314.  
  315.         if (GetRandom(0, 1) == 1)
  316.         {
  317.             horizMoveDelta = -horizMoveDelta;
  318.         }
  319.  
  320.         if (GetRandom(0, 1) == 1)
  321.         {
  322.             vertMoveDelta = -vertMoveDelta;
  323.         }
  324.  
  325.             // set the sprite’s movement characteristics
  326.         SWSetSpriteMoveBounds(testSpriteP, &moveBoundsRect);
  327.         SWSetSpriteMoveDelta(testSpriteP, horizMoveDelta, vertMoveDelta);
  328.         SWSetSpriteMoveProc(testSpriteP, SWBounceSpriteMoveProc);
  329.         SWSetSpriteMoveTime(testSpriteP, kTestSpriteMoveTime);
  330.  
  331.         SWSetSpriteFrameTime(testSpriteP, kTestSpriteFrameTime);
  332.         SWSetSpriteFrameRange(testSpriteP, 0, kNumberOfTestFrames - 1);
  333.         SWSetSpriteFrameAdvance(testSpriteP, GetRandom(0, 1) ? -1 : 1);
  334.  
  335.         SWSetSpriteCollideProc(testSpriteP, SWBounceSpriteCollideProc);
  336.  
  337.             // set the sprite’s initial location
  338.         SWSetSpriteLocation(testSpriteP,
  339.                                     GetRandom(0, moveBoundsRect.right),
  340.                                     GetRandom(0, moveBoundsRect.bottom));
  341.     }
  342.  
  343.     moveBoundsRect = spriteTestP->spriteWorldP->windowFrameP->frameRect;
  344.     SWSetSpriteLocation(spriteTestP->titleSpriteP,
  345.                                 (moveBoundsRect.right / 2) - (spriteTestP->titleFrameP->frameRect.right / 2),
  346.                                 (moveBoundsRect.bottom / 2) - (spriteTestP->titleFrameP->frameRect.bottom / 2));
  347.     SWSetSpriteMoveTime(spriteTestP->titleSpriteP, -1);
  348.  
  349.     spriteTestP->isCommandActive[kSpriteTestTitleCommand] = true;
  350.     spriteTestP->isCommandActive[kBouncingBallsCommand] = true;
  351.     spriteTestP->isCommandActive[kCollisionDetectionCommand] = false;
  352. }
  353.  
  354.  
  355. ///--------------------------------------------------------------------------------------
  356. // SWBounceSpriteCollideProc
  357. ///--------------------------------------------------------------------------------------
  358.  
  359. void SWBounceSpriteCollideProc(
  360.     SpritePtr srcSpriteP,
  361.     SpritePtr dstSpriteP,
  362.     Rect* sectRect)
  363. {
  364.     register short tempDelta;
  365.     Rect rgnRect;
  366.  
  367.         // If both sprites use the same collision routine (this one),ignore the second collision.
  368.     if ((!srcSpriteP->isVisible || !dstSpriteP->isVisible) ||
  369.         ((srcSpriteP->spriteCollideProc == dstSpriteP->spriteCollideProc) &&
  370.         (srcSpriteP > dstSpriteP)))
  371.         return;
  372.  
  373.     rgnRect = (**srcSpriteP->curFrameP->maskRgn).rgnBBox;
  374.  
  375.         // move the mask region to the new sprite location
  376.     OffsetRgn(srcSpriteP->curFrameP->maskRgn,
  377.                 (srcSpriteP->destFrameRect.left - rgnRect.left) +
  378.                 srcSpriteP->curFrameP->offsetPoint.h,
  379.                 (srcSpriteP->destFrameRect.top - rgnRect.top) +
  380.                 srcSpriteP->curFrameP->offsetPoint.v);
  381.  
  382.     rgnRect = (**dstSpriteP->curFrameP->maskRgn).rgnBBox;
  383.  
  384.         // move the mask region to the new sprite location
  385.     OffsetRgn(dstSpriteP->curFrameP->maskRgn,
  386.                 (dstSpriteP->destFrameRect.left - rgnRect.left) +
  387.                 dstSpriteP->curFrameP->offsetPoint.h,
  388.                 (dstSpriteP->destFrameRect.top - rgnRect.top) +
  389.                 dstSpriteP->curFrameP->offsetPoint.v);
  390.  
  391.     SectRgn(srcSpriteP->curFrameP->maskRgn, dstSpriteP->curFrameP->maskRgn, gWorkRgn);
  392.  
  393.     if (!EmptyRgn(gWorkRgn))
  394.     {
  395.         if ((dstSpriteP->horizMoveDelta == 0) && (dstSpriteP->vertMoveDelta == 0))
  396.         {
  397.             if (!((srcSpriteP->destFrameRect.left == sectRect->left) &&
  398.                 (srcSpriteP->destFrameRect.right == sectRect->right)))
  399.             {
  400.                 srcSpriteP->horizMoveDelta = -srcSpriteP->horizMoveDelta;
  401.  
  402.                 SWOffsetSprite(srcSpriteP, srcSpriteP->horizMoveDelta, 0);
  403.             }
  404.  
  405.             if (!((srcSpriteP->destFrameRect.top == sectRect->top) &&
  406.                 (srcSpriteP->destFrameRect.bottom == sectRect->bottom)))
  407.             {
  408.                 srcSpriteP->vertMoveDelta = -srcSpriteP->vertMoveDelta;
  409.  
  410.                 SWOffsetSprite(srcSpriteP, 0, srcSpriteP->vertMoveDelta);
  411.             }
  412.  
  413.             return;
  414.         }
  415.  
  416.             // swap movement delta's
  417.         if (srcSpriteP < dstSpriteP)        // Only one time!
  418.         {
  419.                 // reverse spins.
  420.             srcSpriteP->frameAdvance = -srcSpriteP->frameAdvance;
  421.             dstSpriteP->frameAdvance = -dstSpriteP->frameAdvance;
  422.  
  423.                 // swap h/v delta's
  424.             tempDelta = srcSpriteP->horizMoveDelta;
  425.             srcSpriteP->horizMoveDelta = dstSpriteP->horizMoveDelta;
  426.             dstSpriteP->horizMoveDelta = tempDelta;
  427.  
  428.             tempDelta = srcSpriteP->vertMoveDelta;
  429.             srcSpriteP->vertMoveDelta = dstSpriteP->vertMoveDelta;
  430.             dstSpriteP->vertMoveDelta = tempDelta;
  431.         }
  432.     }
  433. }
  434.  
  435.  
  436. void RunSpriteTest(
  437.     SpriteTestPtr spriteTestP)
  438. {
  439.     SWLockSpriteWorld(spriteTestP->spriteWorldP);
  440.  
  441.     if (spriteTestP->isCommandActive[kCollisionDetectionCommand])
  442.     {
  443.         SWCollideSpriteLayer(spriteTestP->spriteLayerP, spriteTestP->spriteLayerP);
  444.     }
  445.  
  446.     SWProcessSpriteWorld(spriteTestP->spriteWorldP);
  447.     SWAnimateSpriteWorld(spriteTestP->spriteWorldP);
  448.  
  449.     SWUnlockSpriteWorld(spriteTestP->spriteWorldP);
  450. }
  451.  
  452.  
  453. void UpdateSpriteTest(
  454.     SpriteTestPtr spriteTestP)
  455. {
  456.     SWLockSpriteWorld(spriteTestP->spriteWorldP);
  457.     SWUpdateSpriteWorld(spriteTestP->spriteWorldP);
  458.     SWUnlockSpriteWorld(spriteTestP->spriteWorldP);
  459. }
  460.  
  461.  
  462. void HandleSpriteTestTitleCommand(
  463.     SpriteTestPtr spriteTestP)
  464. {
  465.     spriteTestP->isCommandActive[kSpriteTestTitleCommand] =
  466.         !spriteTestP->isCommandActive[kSpriteTestTitleCommand];
  467.  
  468.     if (spriteTestP->isCommandActive[kSpriteTestTitleCommand])
  469.     {
  470.         //SWAddSprite(spriteTestP->spriteLayerP, spriteTestP->titleSpriteP);
  471.         SWSetSpriteVisible(spriteTestP->titleSpriteP, true);
  472.     }
  473.     else
  474.     {
  475.             // erase the sprite (theres got to be an easier way!)
  476.         SWSetSpriteVisible(spriteTestP->titleSpriteP, false);
  477.         //RunSpriteTest(spriteTestP);
  478.  
  479.             // remove the sprite
  480.         //SWRemoveSprite(spriteTestP->spriteLayerP, spriteTestP->titleSpriteP);
  481.     }
  482. }
  483.  
  484.  
  485. void HandleBouncingBallsCommand(
  486.     SpriteTestPtr spriteTestP)
  487. {
  488.     SpritePtr ballSpriteP;
  489.     Boolean isCommandActive;
  490.     long ballNum;
  491.     
  492.     isCommandActive = spriteTestP->isCommandActive[kBouncingBallsCommand] =
  493.         !spriteTestP->isCommandActive[kBouncingBallsCommand];
  494.  
  495.     for (ballNum = 0; ballNum < kNumberOfTestSprites; ballNum++)
  496.     {
  497.         ballSpriteP = spriteTestP->testSpriteArray[ballNum];
  498.  
  499.         SWSetSpriteVisible(ballSpriteP, isCommandActive);
  500.     }
  501. }
  502.  
  503.  
  504. void CopyBitsSpeedTestCommand(
  505.     SpriteTestPtr spriteTestP)
  506. {
  507.     WindowPtr testWindowP = FrontWindow();
  508.     unsigned long frames, seconds, spriteNum;
  509.     long ticks;
  510.  
  511.     HideCursor();
  512.     HideMenuBar(testWindowP);
  513.  
  514.     SWLockSpriteWorld(spriteTestP->spriteWorldP);
  515.     SWUpdateSpriteWorld(spriteTestP->spriteWorldP);
  516.  
  517.     for (spriteNum = 0; spriteNum < kNumberOfTestSprites; spriteNum++)
  518.     {
  519.         SWSetSpriteMoveTime(spriteTestP->testSpriteArray[spriteNum], 0);
  520.         SWSetSpriteFrameTime(spriteTestP->testSpriteArray[spriteNum], 0);
  521.     }
  522.  
  523.     ticks = TickCount();
  524.  
  525.     for (frames = 0; ((TickCount() - ticks) < kTestTime) && (!Button()); frames++)
  526.     {
  527.         SWProcessSpriteWorld(spriteTestP->spriteWorldP);
  528.         SWAnimateSpriteWorld(spriteTestP->spriteWorldP);
  529.     }
  530.  
  531.     seconds = ((TickCount() - ticks) / 60);
  532.  
  533.     for (spriteNum = 0; spriteNum < kNumberOfTestSprites; spriteNum++)
  534.     {
  535.         SWSetSpriteMoveTime(spriteTestP->testSpriteArray[spriteNum], kTestSpriteMoveTime);
  536.         SWSetSpriteFrameTime(spriteTestP->testSpriteArray[spriteNum], kTestSpriteFrameTime);
  537.     }
  538.  
  539.     SWUnlockSpriteWorld(spriteTestP->spriteWorldP);
  540.  
  541.     ShowCursor();
  542.     ShowMenuBar(testWindowP);
  543.  
  544.     DisplayPerformance(frames, seconds);
  545. }
  546.  
  547.  
  548. void BlitPixieSpeedTestCommand(
  549.     SpriteTestPtr spriteTestP)
  550. {
  551.     WindowPtr testWindowP = FrontWindow();
  552.     unsigned long frames, seconds, spriteNum;
  553.     long ticks;
  554.  
  555.     HideCursor();
  556.     HideMenuBar(testWindowP);
  557.  
  558.     SWLockSpriteWorld(spriteTestP->spriteWorldP);
  559.     SWUpdateSpriteWorld(spriteTestP->spriteWorldP);
  560.  
  561.     for (spriteNum = 0; spriteNum < kNumberOfTestSprites; spriteNum++)
  562.     {
  563.         SWSetSpriteMoveTime(spriteTestP->testSpriteArray[spriteNum], 0);
  564.         SWSetSpriteFrameTime(spriteTestP->testSpriteArray[spriteNum], 0);
  565.         SWSetSpriteDrawProc(spriteTestP->testSpriteArray[spriteNum], BlitPixieMaskDrawProc);
  566.     }
  567.  
  568.     SWSetSpriteWorldEraseProc(spriteTestP->spriteWorldP, BlitPixieEraseProc);
  569.     SWSetSpriteWorldDrawProc(spriteTestP->spriteWorldP, BlitPixieDrawProc);
  570.  
  571.     ticks = TickCount();
  572.  
  573.     for (frames = 0; ((TickCount() - ticks) < kTestTime) && (!Button()); frames++)
  574.     {
  575.         SWProcessSpriteWorld(spriteTestP->spriteWorldP);
  576.         SWAnimateSpriteWorld(spriteTestP->spriteWorldP);
  577.     }
  578.  
  579.     seconds = ((TickCount() - ticks) / 60);
  580.  
  581.     for (spriteNum = 0; spriteNum < kNumberOfTestSprites; spriteNum++)
  582.     {
  583.         SWSetSpriteMoveTime(spriteTestP->testSpriteArray[spriteNum], kTestSpriteMoveTime);
  584.         SWSetSpriteFrameTime(spriteTestP->testSpriteArray[spriteNum], kTestSpriteFrameTime);
  585.         SWSetSpriteDrawProc(spriteTestP->testSpriteArray[spriteNum], SWStdDrawProc);
  586.     }
  587.  
  588.     SWSetSpriteWorldEraseProc(spriteTestP->spriteWorldP, SWStdDrawProc);
  589.     SWSetSpriteWorldDrawProc(spriteTestP->spriteWorldP, SWStdMaskDrawProc);
  590.  
  591.     SWUnlockSpriteWorld(spriteTestP->spriteWorldP);
  592.  
  593.     ShowCursor();
  594.     ShowMenuBar(testWindowP);
  595.  
  596.     DisplayPerformance(frames, seconds);
  597. }
  598.  
  599.  
  600. void SpriteTestCommand(
  601.     SpriteTestPtr spriteTestP,
  602.     CWindowPtr srcWindowP)
  603. {
  604.     short x, i;
  605.  
  606.     SetPort((GrafPtr)srcWindowP);
  607.     HideMenuBar((WindowPtr)srcWindowP);
  608.  
  609.     for (x = 0; (x < 1000) && !Button(); x++)
  610.     {
  611.         FillRect(&srcWindowP->portRect, qd.black);
  612.         DisposeSpriteTest(spriteTestP);
  613.         CreateSpriteTest(&spriteTestP, srcWindowP);
  614.         SetupSpriteTest(spriteTestP);
  615.         UpdateSpriteTest(spriteTestP);
  616.  
  617.         for (i = 0; (i < 100) && !Button(); i++)
  618.         {
  619.             SystemTask();
  620.             RunSpriteTest(spriteTestP);
  621.         }
  622.     }
  623.  
  624.     ShowMenuBar((WindowPtr)srcWindowP);
  625. }
  626.  
  627.  
  628. void AdjustSpriteTestMenu(
  629.     SpriteTestPtr spriteTestP,
  630.     MenuHandle spriteTestMenuH)
  631. {
  632.     short commandNumber;
  633.  
  634.     for (commandNumber = 1; commandNumber <= kNumberOfCommands; commandNumber++)
  635.     {
  636.         CheckItem(spriteTestMenuH, commandNumber, spriteTestP->isCommandActive[commandNumber - 1]);
  637.     }
  638.  
  639.         // disable the BlitPixie test if we, are not in 8 bit
  640.     if ((!SWHasColorQuickDraw()) ||
  641.         ((**spriteTestP->spriteWorldP->backFrameP->framePort.colorGrafP->portPixMap).pixelSize != 8))
  642.     {
  643.         DisableItem(spriteTestMenuH, kBlitPixieTestCommand + 1);
  644.     }
  645. }
  646.  
  647.  
  648. void DisplayPerformance(
  649.     long frames,
  650.     long seconds)
  651. {
  652.     Str255 framesString, secondsString, fpsString;
  653.     long fps;
  654.     
  655.     NumToString(frames, framesString);
  656.     NumToString(seconds, secondsString);
  657.  
  658.     fps = (seconds > 0) ? frames / seconds : frames;
  659.     NumToString(fps, fpsString);
  660.  
  661.     ParamText(framesString, secondsString, fpsString, "\p");
  662.     NoteAlert(kPerformanceAlertID, NULL);
  663. }
  664.  
  665.  
  666.